package com.car.server.impl;

import com.car.dao.impl.AdminPagCarDaoImpl;
import com.car.domain.Car;
import com.car.domain.Page;
import com.car.server.AdminPageCarServer;

import java.util.List;

public class AdminPageCarServerImpl implements AdminPageCarServer {
    @Override
    public Page<Car> findPageByCurrentPage(Integer currentPage, Integer pageSize) {
        //1.创建PageBean对象,封装分页数据
        Page<Car> pageBean = new Page<Car>();
        //2.封装当前页码数字
        pageBean.setCurrentPage(currentPage);
        //3.封装每页显示的具体条数
        pageBean.setPageSize(pageSize);
        //4.封装每页显示的具体数据
        List<Car> list = new AdminPagCarDaoImpl().adminPageCar(currentPage, pageSize);
        pageBean.setList(list);
        //5.封装总的条数
        Number num= new AdminPagCarDaoImpl().adminCarAllCount();
        int number=num.intValue();
        pageBean.setTotalCount(number);
        //6.封装总的页码数: 总的条数101  每页显示10条
        Integer totalPage  = (number%pageSize==0)?
                number/pageSize : ((number/pageSize)+1);
        pageBean.setTotalPage(totalPage);
        return pageBean;
    }
}
